Uint32 preTime=0,countFrame=0,timeAccumulaion=0;
int timeToDelay=0;
std::string title;

void FPS_Delay(){
    countFrame++;
    //计算距离当前进行帧结束还有多少时间
    timeToDelay=(int)(tpf-(SDL_GetTicks()-preTime));
    timeAccumulaion+=timeToDelay>0?tpf:(tpf-timeToDelay);
    //准备延时的时间,为负代表当前帧超时,不作延时
    timeToDelay=timeToDelay>0?timeToDelay:0;
    if(timeAccumulaion>1000){//累积时间满一秒更新标题
        title=std::string("CuBe      countFrameps:")
             +std::to_string(countFrame);
        SDL_SetWindowTitle(window,title.data());
        timeAccumulaion=0;countFrame=0;
    }
    SDL_Delay(timeToDelay);
    preTime=SDL_GetTicks();
}